home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / GETNAME.SLT < prev    next >
Text File  |  1991-01-26  |  6KB  |  196 lines

  1. //-----------------------------------------------------------
  2. // GETNAME.SL? Get variables from the NAME.DAT file.
  3. //
  4. // Author: Inge Vabekk
  5. //         Hamangskogen 108
  6. //         N-1300 SANDVIKA
  7. //         NORWAY
  8. //-----------------------------------------------------------
  9.  
  10. str namefile  [12]= "NAME.DAT"    // File containing name etc.
  11.    ,fonedir   [12]= "TELIX.FON"   // Default phone directory
  12.    ,global      []= "GLOBAL"      // Name of global script
  13.    ,name        []= "NAME"        // Global: User name.
  14.    ,mdir        []= "MDIR"        // Global: Mail directory.
  15.    ,errormess [80]                // For error message.
  16.    ,inputline[160]                // For reading NAME.DAT file.
  17.    ,varname    [6]
  18.    ;                                     
  19.  
  20. int file                          // File handle
  21.    ,namelen=6                     // Length of names
  22.    ,stringlen=80                  // Max. length of variables
  23.    ;
  24.  
  25. //-----------------------------------------------------------
  26. // Script starts here.
  27. //-----------------------------------------------------------
  28.  
  29. main ()
  30. {
  31. int c, l;
  32.  
  33.   if (!is_loaded(global))                // If Global script is not
  34.     return(-1);                          // loaded: Error.
  35.  
  36.   clear_scr();
  37.   box ( 8,6,60,14,2,0,15);
  38.   box (10,7,58,13,2,0,15);
  39.   box (12,8,56,12,2,0,15);
  40.   pstraxy ("Please wait a sec... I'm reading data....",14,10,116);
  41.   gotoxy(0,0);
  42.  
  43.   if ((file=fopen(namefile,"r"))<=0) 
  44.   { errormess = namefile;
  45.     strcat (errormess," not found!");
  46.     status_wind (errormess,20);          // Show error message.
  47.     return (-1);
  48.   }
  49.   write ("Prompt"," Command");           // Set default command prompt.
  50.  
  51. // Read the NAME.DAT file.
  52.  
  53.   while (fgets(inputline,160,file)>0)    // Get input line.
  54.     codeset ();                          // Find and set the code.
  55.  
  56.   fclose (file);                         // Close the file
  57.  
  58. // Set user keys.
  59.  
  60.   if (getkey ("f1",inputline) > 0)       // F1 key.
  61.     setkey (0x3b00,inputline);
  62.   if (getkey ("f2",inputline) > 0)       // F2 key.
  63.     setkey (0x3c00,inputline);
  64.   if (getkey ("f3",inputline) > 0)       // F3 key.
  65.     setkey (0x3d00,inputline);
  66.   if (getkey ("f4",inputline) > 0)       // F4 key.
  67.     setkey (0x3e00,inputline);
  68.   if (getkey ("f5",inputline) > 0)       // F5 key.
  69.     setkey (0x3f00,inputline);
  70.   if (getkey ("f6",inputline) > 0)       // F6 key.
  71.     setkey (0x4000,inputline);
  72.   if (getkey ("f7",inputline) > 0)       // F7 key.
  73.     setkey (0x4100,inputline);
  74.   if (getkey ("f8",inputline) > 0)       // F8 key.
  75.     setkey (0x4200,inputline);
  76.   if (getkey ("f9",inputline) > 0)       // F9 key.
  77.     setkey (0x4300,inputline);
  78.   if (getkey ("f10",inputline) > 0)      // F10 key.
  79.     setkey (0x4400,inputline);
  80.   if (getkey ("f11",inputline) > 0)      // F11 key.
  81.     setkey (0x8500,inputline);
  82.   if (getkey ("f12",inputline) > 0)      // F12 key.
  83.     setkey (0x8600,inputline);
  84.  
  85.   read ("Graph",inputline);              // Graphics?
  86.   setchr(inputline,1,0);                 // Set graphics, Y or N.
  87.   strupper(inputline);
  88.   if (inputline != "Y") inputline = "N";
  89.   write ("Graph",inputline);
  90.  
  91.   if (read ("Fdir",errormess) < 0)       // phone directory,
  92.     write ("Fdir",fonedir);
  93.  
  94.   read (mdir,errormess);                 // Mail directory
  95.   for (l=strlen(errormess)-1; l>0; --l)
  96.   { if (subchr(errormess,l) !='\')
  97.       break;
  98.     setchr (errormess,l,0);              // Delete trailing slash.
  99.   }
  100.   run ("CRDIR",errormess,2);             // Create directory.
  101.   strcat (errormess,"\");                // Add slash again.
  102.   write (mdir,errormess);                // Set mail directory
  103.   return (0);                            // and return.
  104. }
  105.  
  106. //-----------------------------------------------------------
  107. // Routine to decode one line from the input file.
  108. //-----------------------------------------------------------
  109.  
  110. codeset()
  111. {
  112. int i, j, k, l, c, copo; 
  113.  
  114.   copo = strchr(inputline,0,':');        // Find first colon.
  115.   if (copo < 0) return(0);               // Not found!
  116.  
  117.   if ((k=strchr(inputline,0,'{')) >= 0)    // Comment in this line?
  118.   { if ((l=strchr(inputline,k,'}')+1) > k) // End of comment found?
  119.     { substr (inputline,l,80,errormess); // Move rest to temp.
  120.       copystr (errormess,inputline,k,80);// Back to input line.
  121.     }
  122.   }
  123.  
  124.   for (i=j=0; i < copo; ++i)
  125.   { if ((c=subchr(inputline,i)) != ' ')
  126.     { setchr (varname,j,toupper(c));     // Copy all except space.
  127.       if (++j >= namelen)                // Protect against too long
  128.         break;                           // strings.
  129.     }
  130.   }
  131.   for (; j < namelen; ++j)               // Add spaces.
  132.     setchr (varname,j,' ');
  133.  
  134. // Isolate contents of variable. Find first non-space after colon.
  135.  
  136.   while ((c=subchr(inputline,++copo))>0)
  137.     if (c > ' ') break;                  // Non-space found.
  138.  
  139.   if (c < ' ') return(0);                // Invalid input.
  140.  
  141.   l = strlen(inputline);
  142.   for ( ; l>=copo; --l)  
  143.     if (subchr(inputline,l) != ' ')      // Remove trailing spaces.
  144.       break;
  145.    
  146.   setchr(inputline,++l,0);               // Insert terminator.
  147.  
  148. //  Move string down to start at 0.
  149.  
  150.   substr (inputline,copo,stringlen,inputline);
  151.   write (varname,inputline);             // Define this global.
  152.  
  153.   return(0);
  154. }
  155.  
  156. //-----------------------------------------------------------
  157. // Get a softkey.
  158. //-----------------------------------------------------------
  159.  
  160. getkey (str key, str varname) 
  161. {
  162.   read (key,varname);
  163.   if (strcmpi (varname,"@name") == 0)  // Replace "@name" by name.
  164.   { read (name,varname);
  165.     strcat (varname,"^M");
  166.   }
  167. }
  168.  
  169. //-----------------------------------------------------------
  170. // Read a variable.
  171. //-----------------------------------------------------------
  172.  
  173. read (str name, str varname)
  174. {
  175.   return (call (global,"R",name,varname));
  176. }
  177.  
  178. //-----------------------------------------------------------
  179. // Write a variable.
  180. //-----------------------------------------------------------
  181.  
  182. write(str name, str varname)
  183.   return (call (global,"W",name,varname));
  184. }
  185.  
  186. //-----------------------------------------------------------
  187. // Set a key.
  188. //-----------------------------------------------------------
  189.  
  190. setkey (int key, str string)
  191.   if (strlen(string) > 0)
  192.     keyset (key,0,string);
  193. }
  194.